home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #3
/
Amiga Plus CD - 2002 - No. 03.iso
/
AmiSoft
/
Util
/
Arc
/
Checkx.lha
/
CheckX
/
sources
/
StartCode.a
< prev
next >
Wrap
Text File
|
2002-12-30
|
1KB
|
55 lines
INCLUDE AINCLUDE:IncDirs.i
INCLUDE exec/libraries.i
INCLUDE exec/tasks.i
INCLUDE exec/memory.i
INCLUDE lvo/exec_lib.i
SECTION "StartCode",CODE
XREF @start
* Could not do that in main program, because of C language limitations
*
* This is not required (e.g. You can compile the main program without that
* start header), but may increase stability for files with really deep
* recursion (I have a file with up to 23 link levels).
STACKSIZE EQU 10240
MOVEA.L 4.W,A6
MOVEQ #37,D0
CMP.W LIB_VERSION(A6),D0 * we need OS2.0 to use StackSwap
BHI.B start
MOVE.L #STACKSIZE,D2
SUBA.L A1,A1
JSR _LVOFindTask(A6)
MOVE.L D0,A0
MOVE.L TC_SPUPPER(A0),D0 * calculate current size
SUB.L TC_SPLOWER(A0),D0
CMP.L D2,D0
BGE.B start * enough ? then do nothing
MOVE.L D2,D0
MOVEQ #MEMF_PUBLIC,D1
JSR _LVOAllocMem(A6) * get memory
MOVE.L D0,D3
BEQ.B start * failed ? call without StackSwap
LEA -StackSwapStruct_SIZEOF(A7),A7
MOVE.L A7,A4
MOVE.L D0,stk_Lower(A4) * initialize StackSwapStruct
ADD.L D2,D0
MOVE.L D0,stk_Upper(A4)
MOVE.L D0,stk_Pointer(A4)
MOVEA.L A4,A0
JSR _LVOStackSwap(A6) * swap stack
JSR @start(PC) * call main function
MOVE.L D0,D6
MOVEA.L A4,A0
JSR _LVOStackSwap(A6) * swap stack back
LEA StackSwapStruct_SIZEOF(A7),A7
MOVEA.L D3,A1
MOVE.L D2,D0
JSR _LVOFreeMem(A6) * free stack
MOVE.L D6,D0 * set return code
RTS
start JMP @start(PC)
END